Skip to content

Conversation

@corbob
Copy link
Member

@corbob corbob commented Sep 19, 2025

Description Of Changes

Update the check for .Net version to happen before the container is initialized.

Motivation and Context

If .Net is sufficiently old, the container initialization fails and does not provide helpful context.

Testing

Operating Systems Testing

  • Windows 11 - manual verification of the issue
  • Windows Server 2019 - Test Kitchen
  • Windows Server 2016 - Test Kitchen

Change Types Made

  • Bug fix (non-breaking change).
  • Feature / Enhancement (non-breaking change).
  • Breaking change (fix or feature that could cause existing functionality to change).
  • Documentation changes.
  • PowerShell code changes.

Change Checklist

  • Requires a change to the documentation.
  • Documentation has been updated.
  • Tests to cover my changes, have been added.
  • All new and existing tests passed?
  • PowerShell code changes: PowerShell v3 compatibility checked?

Related Issue

Fixes #3228

Reason for Draft

I am still validating the Test Kitchen tests, and working on if others should be added.

@corbob
Copy link
Member Author

corbob commented Sep 19, 2025

For our future selves: When I said "where I think this is happening (or at least relatively close)" in #3228, what I mean by the relatively close part is that if I set the .Net registry key such that Chocolatey CLI will fail with this error, Visual Studio will not load properly, and so debugging is not really feasible. However: the logs all encounter this error during the container registration, so the change I made is to verify the .Net version before container registration. One side effect of this is that termination of the program occurs before Chocolatey outputs it's version information, however given that the alternative is for it to terminate before Chocolatey outputs it's version information with an altogether entirely unhelpful error, this seems like a happy middle ground.

vexx32
vexx32 previously approved these changes Sep 22, 2025
Copy link
Member

@vexx32 vexx32 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I'm pretty happy with these changes overall. Will have to see how test runs go but on the whole this approach looks like a good way to go here.

There are instances where .Net is not installed in a way that allows
Chocolatey CLI to function. In these scenarios, the version in the
registry seems to be very old. This commit accounts for this by wrapping
the container registration in a try cath, and displaying a descriptive
error in that case.

Additionally, this changes the check to use Registry64 instead of
Registry32, as on 64 bit systems the 64 bit registry is the one that
determines the .Net version. And the lookup on 32 bit systems gracefully
falls back to the 32 bit registry.
This updates the .Net version Pester test to use the 64 bit registry as
that is the one that Chocolatey CLI is using. Further, it adds a test
for the .Net version to be a low integer instead of deleting it. It's
been found in some scenarios where the version is there but low .Net
misbehaves. It also adds a retry onto taking ownership of the registry
key as we've seen instances where it fails to take the ownership and so
the test fails. This retry should hopefully resolve these sporadic
failures.
@corbob
Copy link
Member Author

corbob commented Sep 23, 2025

I think I'm pretty happy with these changes overall. Will have to see how test runs go but on the whole this approach looks like a good way to go here.

I mixed up the version from the config, so a number of the tests failed. I've updated the description with the latest Test Kitchen runs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Error: Unable to load one or more of the requested types. Retrieve the LoaderExceptions property for more information.

2 participants